// 需要加签的 taskConfigId
import { isArray } from 'lodash';
import { isApprovalTaskDone } from '../components/Progress/list/item/TaskNode';
import { useApprovalProvide } from './index';
export const useAddSign = () => {
  const { progressData } = useApprovalProvide();
  // 当前的审批任务中是否包含加签
  const isAddSign = computed(() => {
    if (!progressData.value) return false;
    return !!progressData.value.taskActivities?.find((item) => {
      // 后端配置 任务是否可加签
      const canAddSign = item.canAddSign;

      // 是否为多人审批（单个任务有多个审批人）
      let isMultiplePeople = false;
      // 是否为审批中任务
      const isDoing = item?.userTasks?.find((task) => {
        const { approvalStatus, endTime, assigneeUsers } = task;
        const doing = !isApprovalTaskDone(approvalStatus, endTime);
        if (isArray(assigneeUsers) && assigneeUsers.length > 1) {
          if (doing) {
            isMultiplePeople = true;
          }
        }
        return doing;
      });
      return canAddSign && isDoing && !isMultiplePeople;
    });
  });
  return {
    isAddSign
  };
};
